package hos.table.simple;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.evrencoskun.tableview.adapter.recyclerview.holder.AbstractViewHolder;

import java.util.ArrayList;
import java.util.List;

import hos.table.BaseTableAdapter;
import hos.table.R;

/**
 * <p>Title: SimpleTableAdapter </p>
 * <p>Description:  </p>
 * <p>Company: www.mapuni.com </p>
 *
 * @author : 蔡俊峰
 * @version : 1.0
 * @date : 2022/7/7 22:06
 */
public class SimpleTableAdapter extends BaseTableAdapter {

    private final boolean isRanking;

    private final List<SimpleColumnHeaderViewHolder> mHeaderList = new ArrayList<>();


    public SimpleTableAdapter() {
        this(false);
    }

    public SimpleTableAdapter(boolean isRanking) {
        this.isRanking = isRanking;
    }

    @NonNull
    public List<SimpleColumnHeaderViewHolder> getHeaderList() {
        return mHeaderList;
    }

    @NonNull
    @Override
    public AbstractViewHolder onCreateCellViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SimpleCellViewHolder(View.inflate(parent.getContext(), R.layout.simple_table, null));
    }

    @NonNull
    @Override
    public AbstractViewHolder onCreateColumnHeaderViewHolder(@NonNull ViewGroup parent, int viewType) {
        SimpleColumnHeaderViewHolder viewHolder;
        if (isRanking) {
            viewHolder = new SimpleColumnHeaderViewHolder(this, View.inflate(parent.getContext(), R.layout.simple_table_ranking, null), isRanking);
        } else {
            viewHolder = new SimpleColumnHeaderViewHolder(this, View.inflate(parent.getContext(), R.layout.simple_table, null));
        }
        if (!mHeaderList.contains(viewHolder)) {
            mHeaderList.add(viewHolder);
        }
        return viewHolder;
    }

    @NonNull
    @Override
    public AbstractViewHolder onCreateRowHeaderViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SimpleRowHeaderViewHolder(View.inflate(parent.getContext(), R.layout.simple_table, null), isRanking);
    }

    @NonNull
    @Override
    public View onTitleView(Context context, String title) {
        return new SimpleTitleTableHolder().onBindView(context, this,title);
    }
}
